var base = require('conf.js')
var request = new Object();
var app = getApp();
const APP_ID = 'wxd685236c412813d0';//输入小程序appid
const APP_SECRET = '6f069ab3a373b8d65351a70b55d9936c';//输入小程序app_secret
var OPEN_ID = ''//储存获取到openid
var SESSION_KEY = ''//储存获取到session_key


request.register = function () {
  wx.login({
    success: function (res) {
      var codeid = res.code
      wx.request({
        //获取openid接口
        //url: 'http://192.168.43.66/front/wx/dmz/openid',
        url: 'http://119.23.79.90:8080/tgl/front/wx/dmz/openid',
        method: 'GET',
        data:{code:codeid},
        header: {
          "Content-Type": "application/x-www-form-urlencoded",
          //"WyxSoapHeader": token_Date
        },
        success: function (res) {
          console.log(res)
        }
      })
    }
  })
}

request.wxRequest = function (obj) {
  var code = wx.getStorageSync('access_token')
  wx.request({
    url: base.url + obj.url,
    data: obj.data,
    method: obj.method,
    header: {
      "Content-Type": "application/json;charset=UTF-8",
      'userToken': base.token_Date
    },
    success: function (res) {
      console.log(res.data.data)
      if (res.statusCode == 200 && res.data.code == 'success') {
        typeof (obj.success) == 'function' && obj.success(res.data.data);
      }
    }
  })
}
module.exports = request